package cn.wolfcode.web.interceptor;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginLinterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {


        //判断是否有等陆
        HttpSession session = request.getSession();
        Employee employee =UserContext.getCurrentUser();

        //如果有就放行
        if (employee != null) {
            return true;
        }

        //没有就跳到登陆页面(不放行)
        response.sendRedirect("/login.html");
        return false;


    }
}
